﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Codemo.Core.Applications;

namespace Codemo.Core.Deployment.Tasks
{
    /// <summary>
    /// 
    /// </summary>
    public class TaskFactory
    {
        /// <summary>
        /// Generates the tasks.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="deploymentConfigurationVersion">The application version.</param>
        /// <param name="deploymentTarget">The deployment target.</param>
        /// <param name="package">The package.</param>
        /// <returns></returns>
        public IList<DeploymentTask> GenerateTasks(Application application, DeploymentConfigurationVersion deploymentConfigurationVersion,
                                                    DeploymentTarget deploymentTarget, Package package)
        {
            IList<DeploymentTask> deploymentTasks = new List<DeploymentTask>();

            foreach (TaskType taskType in deploymentConfigurationVersion.DeploymentTasks)
            {
                deploymentTasks.Add(GenerateTask(application, deploymentConfigurationVersion, deploymentTarget, package, taskType));
            }

            return deploymentTasks;
        }

        /// <summary>
        /// Generates the task.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="deploymentConfigurationVersion">The application version.</param>
        /// <param name="deploymentTarget">The deployment target.</param>
        /// <param name="package">The package.</param>
        /// <param name="taskType">Type of the task.</param>
        /// <returns></returns>
        public DeploymentTask GenerateTask(Application application, DeploymentConfigurationVersion deploymentConfigurationVersion,
                                                    DeploymentTarget deploymentTarget, Package package, TaskType taskType)
        {
            switch (taskType)
            {

                case TaskType.CopyPackageToTemporaryDirectory:
                    return new ExtractToTempDirectoryTask(application, deploymentConfigurationVersion, deploymentTarget, package);
                default:
                    throw new UnsupportedTaskTypeException(taskType.ToString());
            }
        }
    }
}
